<?php
include '../include/functions.php';
//set session save path
	session_save_path($session_path);
	// Initialize a session. 
	session_start();
	$count++;
	$sessionId = session_id();
?>
<!DOCTYPE html PUBLIC "-//W3C//Dtd html 4.01 Transitional//EN"
"http://www.w3.org/tr/html4/loose.dtd">
<html><!-- InstanceBegin template="/Templates/MAIN.dwt.php" codeOutsideHTMLIsLocked="false" -->
  <head>
    <!-- InstanceBeginEditable name="doctitle" -->
    <title>JoshHughes.com NFL Football Pool</title>
    <!-- InstanceEndEditable -->
	<link rel="stylesheet" href="../css/football.css" type="text/css">
    <script src="../scripts/prototype.js" type="text/javascript"></script>
	<script src="../scripts/scriptaculous.js" type="text/javascript"></script>
	<script type="text/javascript">
	// Dynamic Iframe loader
	function loadmonkeyframe(theURL)
	{
		document.getElementById("monkeyframe").src=theURL;
	}
	function loadpollframe(theURL)
	{
		document.getElementById("pollframe").src=theURL;
	}
	
	// resizes Iframe according to content
	function resizeMe(obj){ 
	docHeight = obj.document.body.scrollHeight
	 obj.style.height = docHeight + 5 + 'px'
	 } 
	</script>
    <!-- InstanceBeginEditable name="head" --><!-- InstanceEndEditable -->
  </head>
<body>
<div id="pagewidth" >
	<div id="header" >
	
		<?PHP include_once("layout/header.html"); ?>
		
	</div>
			<div id="wrapper" class="clearfix" > 
			<div id="maincol" >

			<!-- InstanceBeginEditable name="Contents" -->

				<?php
				
					if($Submit)
					{
						//Connect To Database
						dbConnect();
						
						//Write SQL Query to extract specified data
						$SQL = "SELECT Fname, Lname, Email FROM NFLUsers WHERE ID=$userID";
						//Open Record Set using SQL Query
						$result = mysql_query($SQL) or die("Cannot query the database.<br>" . mysql_error());
						$From = mysql_fetch_array($result);
						if($From["Email"])
						{
							$FromName = $From["Fname"]." ".$From["Lname"];
							$FromEmail = $From["Email"];
						}
						
						//set up some email varibables
						$URL = "http://football.joshhughes.com";
						$MailFrom = "From: Football@joshhughes.com";
						$MailSubject = "$FromName has invited you to the pool!";
						$MailBody = "$ToName,\n$FromName has invited you to check out the football pool at $URL.";
						$HTMLMailBody = "<b><i>$ToName</i></b>,<br/><b>$FromName</b> has invited you to check out the football pool at <a href=\"$URL\">$URL</a>.";
						
						if($Note)
						{
							$MailBody.= "  Here's what $FromName had to say:\n\n$Note";
							$HTMLMailBody.= "  Here's what <b>$FromName</b> had to say:<br/><br/><i>$Note</i><br/><br/>";
						}
				
						$MailBody.= "\n\nThis is just a site to have fun to try and pick the winners of every game week by week.  Playing in the pool is easy with simple forms to make your picks, reminder emails prior to games, and Weekly breakdowns to see how each member did that week.  Go to $URL and look around, if you want to play click the \"Register\" link at the top of the page and sign up.";
						$HTMLMailBody.= "<br/><br/>This is just a site to have fun to try and pick the winners of every game week by week.  Playing in the pool is easy with simple forms to make your picks, reminder emails prior to games, and Weekly breakdowns to see how each member did that week.  Go to <a href=\"$URL\">$URL</a> and look around, if you want to play click the <a href=\"$URL/register.php\">&quot;register&quot;</a> link at the top of the page and sign up.";
						
						$MailTo = $ToEmail;
						//add From: header
						$headers = "From: $FromEmail\r\n";
				
						//specify MIME version 1.0
						$headers .= "MIME-Version: 1.0\r\n";
				
						//unique boundary
						$boundary = uniqid("HTMLDEMO");
						
						//tell e-mail client this e-mail contains//alternate versions
						$headers .= "Content-Type: multipart/alternative" ."; boundary = $boundary\r\n\r\n";
						
						//message to people with clients who don't
						//understand MIME
						$headers .= "This is a MIME encoded message.\r\n\r\n";
				
						//plain text version of message
						$headers .= "--$boundary\r\n" .
						   "Content-Type: text/plain; charset=ISO-8859-1\r\n" .
						   "Content-Transfer-Encoding: base64\r\n\r\n";
						$headers .= chunk_split(base64_encode($MailBody));
				
						//HTML version of message
						$headers .= "--$boundary\r\n" .
						   "Content-Type: text/html; charset=ISO-8859-1\r\n" .
						   "Content-Transfer-Encoding: base64\r\n\r\n";
						$headers .= chunk_split(base64_encode($HTMLMailBody));
				
						//Send an Email notifying user of games to pick.
						//mail($MailTo, $MailSubject, "", $headers);
						mail($MailTo, $MailSubject, $MailBody, $MailFrom);  //message send
				
						//message send
						echo "<H1>Message Sent to: $ToName (<i>$MailTo</i>)</H1>$HTMLMailBody";
				
					}
					else
					{
					?>
					<link rel="stylesheet" href="../css/NFLPool.css" type="text/css">
					<table width="500" cellpadding="5" cellspacing="0">
					<tr>
					<td class="redbg" align="Center"><span class="whitelink">Invite a Friend to the Pool</span></td>
					  </tr>
						<td class="redbg" align="Left">
						<form name="inviteForm" action="<?PHP echo $PHP_SELF; ?>" method="POST">
						   <table width="500" border="0" cellspacing="3" cellpadding="3" border="0" bgcolor="#FFFFFF">
							<tr> 
										<td height="25">
								<B>Friend's Name:</B>
								</td>
										<td height="25">
								<input type="text" name="ToName">
								</td>
							</tr>
							<tr> 
										<td height="25">
								<B>Friend's Email:</B>
								</td>
										<td height="25">
								<input type="text" name="ToEmail">
								</td>
							</tr>
							<tr> 
										<td height="25" valign="top">
								<B>Your<br />Message:</B>
								</td>
										<td height="25">
								<textarea name="Note" rows="5" style="width:250"></textarea>
								</td>
							</tr>
							<tr> 
										<td height="25" colspan="2"><div align="center"> 
								<input type="submit" name="Submit" value="Invite">
								<input type="reset" name="Submit2" value="Reset Form"></div>
								</td>
							</tr>
		    </table>
						 </form>
						</td>
					  </tr>
					</table>
					<?	
					}//end if($Submit)
				?>

			<!-- InstanceEndEditable -->
			
			</div>
			<div id="leftcol" >
			
				<?PHP include_once("layout/left_column.php"); ?>
		
			</div>
			
		</div>
		
		<div id="footer" >
		
			<?PHP include_once("layout/footer.html"); ?>
			
		</div>
</div>
</body>
<!-- InstanceEnd --></html>